home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / role / Ang261Lib.lha / src / create.c < prev    next >
C/C++ Source or Header  |  1994-10-22  |  23KB  |  913 lines

  1. /*
  2.  * create.c: create a player character 
  3.  *
  4.  * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke 
  5.  *
  6.  * This software may be copied and distributed for educational, research, and
  7.  * not for profit purposes provided that this copyright and statement are
  8.  * included in all such copies. 
  9.  */
  10.  
  11. #include "constant.h"
  12. #include "types.h"
  13. #include "config.h"
  14. #include "externs.h"
  15.  
  16. #ifdef USG
  17. #ifndef ATARIST_MWC
  18. #include <string.h>
  19. #endif
  20. #else
  21. #include <strings.h>
  22. #endif
  23.  
  24. /* Lets do all prototypes correctly.... -CWS */
  25. #ifndef NO_LINT_ARGS
  26. #ifdef __STDC__
  27. static void change_stat(int, int);
  28. static int  monval(int);
  29.  
  30. #else
  31. static void change_stat();
  32. static int  monval();
  33.  
  34. #endif
  35.  
  36. static void get_stats();
  37. static void set_prev_stats();
  38. static int  get_prev_stats();
  39. static void get_all_stats();
  40. static void put_auto_stats();
  41. static void choose_race();
  42. static void print_history();
  43. static void set_prev_history();
  44. static void get_prev_history();
  45. static void get_sex();
  46. static void get_ahw();
  47. static void set_prev_ahw();
  48. static void get_prev_ahw();
  49. static void get_class();
  50. static void get_class_choice();
  51. static void get_money();
  52.  
  53. #endif
  54.  
  55. struct previous {
  56.     int16u age;
  57.     int16u wt;
  58.     int16u ht;
  59.     int16  disarm;
  60.     int16u stat[6];
  61.     int16u sc;
  62.     char   history[4][60];
  63.     background_type     bg;
  64. }      prev;
  65.  
  66. extern int peek;
  67.  
  68. /* Generates character's stats            -JWT-     */
  69. static void
  70. get_stats()
  71. {
  72.     register int i, tot;
  73.     int dice[18];
  74.  
  75.     do {
  76.     tot = 0;
  77.     for (i = 0; i < 18; i++) {
  78.         dice[i] = randint(3 + i % 3); /* Roll 3,4,5 sided dice once each */
  79.         tot += dice[i];
  80.     }
  81.     }
  82.     while (tot <= 42 || tot >= 54);
  83.     
  84.     for (i = 0; i < 6; i++)
  85.     py.stats.max_stat[i] = 5 + dice[3 * i] + dice[3 * i + 1] +
  86.         dice[3 * i + 2];
  87. }
  88.  
  89.  
  90. /* Returns adjusted stat                                       -JK-  */
  91. /* Algorithm by ...                                            -JWT- */
  92. /* Used by change_stats and auto_roller
  93.  * auto_roll is boolean and states maximum changes
  94.  * should be used rather than random ones
  95.  * to allow specification of higher values to wait for
  96.  */
  97.  
  98. static int
  99. adjust_stat(stat_value, amount, auto_roll)
  100. int stat_value;
  101. int16 amount;
  102. int auto_roll;
  103. {
  104.   register int i;
  105.  
  106.   if (amount < 0)
  107.     for (i = 0; i > amount; i--)
  108.       {
  109. /* OK so auto_roll conditions not needed for negative amounts since stat_value
  110.  * is always 15 at least currently!  -JK
  111.  */
  112.                 
  113.              if (stat_value > 108)
  114.                stat_value--;
  115.              else if (stat_value > 88)
  116.                  stat_value -= ((auto_roll ? 6 : randint(6)) + 2);
  117.              else if (stat_value > 18)
  118.                {
  119.                  stat_value -= ((auto_roll ? 15 : randint(15)) + 5);
  120.                  if (stat_value < 18)
  121.                    stat_value = 18;
  122.                }
  123.              else if (stat_value > 3)
  124.                stat_value--;
  125.       }
  126.   else
  127.     for (i = 0; i < amount; i++)
  128.       {
  129.         if (stat_value < 18)
  130.           stat_value++;
  131.         else if (stat_value < 88)
  132.           stat_value += ((auto_roll ? 15 : randint(15)) + 5);
  133.         else if (stat_value < 108)
  134.           stat_value += ((auto_roll ? 6 : randint(6)) + 2);
  135.         else if (stat_value < 118)
  136.           stat_value++;
  137.       }
  138.   return stat_value;
  139. }
  140.  
  141.  
  142. /* Changes stats by given amount                                -JWT-   */
  143. static void change_stat(stat, amount)
  144. int stat;
  145. int amount;
  146. {
  147.   py.stats.max_stat[stat] =
  148.         adjust_stat(py.stats.max_stat[stat], (int16) amount, FALSE);
  149. }
  150.  
  151.  
  152. static void
  153. set_prev_stats()
  154. {
  155.     register int        i;
  156.  
  157.     for (i = 0; i < 6; i++)
  158.     prev.stat[i] = (int16u) py.stats.max_stat[i];
  159.  
  160.     return;
  161. }
  162.  
  163.  
  164. static int
  165. get_prev_stats()
  166. {
  167.     register int        i;
  168.  
  169.     if (!prev.stat[0])
  170.     return 0;
  171.     for (i = 0; i < 6; i++) {
  172.     py.stats.cur_stat[i] = (py.stats.max_stat[i] = prev.stat[i]);
  173.     py.stats.use_stat[i] = prev.stat[i];
  174.     }
  175.     py.misc.ptodam = todam_adj();
  176.     py.misc.ptohit = tohit_adj();
  177.     py.misc.pac = toac_adj();
  178.     prev.stat[0] = 0;
  179.     return 1;
  180. }
  181.  
  182.  
  183. /*
  184.  * generate all stats and modify for race. needed in a separate module so
  185.  * looping of character selection would be allowed     -RGM- 
  186.  */
  187. static void
  188. get_all_stats()
  189. {
  190.     register player_type *p_ptr;
  191.     register race_type *r_ptr;
  192.     register int        j;
  193.  
  194.     p_ptr = &py;
  195.     r_ptr = &race[p_ptr->misc.prace];
  196.     get_stats();
  197.     change_stat(A_STR, r_ptr->str_adj);
  198.     change_stat(A_INT, r_ptr->int_adj);
  199.     change_stat(A_WIS, r_ptr->wis_adj);
  200.     change_stat(A_DEX, r_ptr->dex_adj);
  201.     change_stat(A_CON, r_ptr->con_adj);
  202.     change_stat(A_CHR, r_ptr->chr_adj);
  203.     for (j = 0; j < 6; j++) {
  204.     py.stats.cur_stat[j] = py.stats.max_stat[j];
  205.     py.stats.use_stat[j] = modify_stat(j, py.stats.mod_stat[j]);
  206.     }
  207.  
  208.     p_ptr->misc.srh = r_ptr->srh;
  209.     p_ptr->misc.bth = r_ptr->bth;
  210.     p_ptr->misc.bthb = r_ptr->bthb;
  211.     p_ptr->misc.fos = r_ptr->fos;
  212.     p_ptr->misc.stl = r_ptr->stl;
  213.     p_ptr->misc.save = r_ptr->bsav;
  214.     p_ptr->misc.hitdie = r_ptr->bhitdie;
  215.     p_ptr->misc.lev = 1;
  216.     p_ptr->misc.ptodam = todam_adj();
  217.     p_ptr->misc.ptohit = tohit_adj();
  218.     p_ptr->misc.ptoac = 0;
  219.     p_ptr->misc.pac = toac_adj();
  220.     p_ptr->misc.expfact = r_ptr->b_exp;
  221.     p_ptr->flags.see_infra = r_ptr->infra;
  222. }
  223.  
  224. /* copied from misc2.c, so the display loop would work nicely -cft */
  225. static const char *stat_names[] = {"STR: ", "INT: ", "WIS: ", "DEX: ", "CON: ", "CHR: "};
  226.  
  227.  
  228. #ifdef AUTOROLLER
  229. /* used for auto-roller.  Just put_stats(), w/o the extra info -CFT */
  230. static void
  231. put_auto_stats()
  232. {
  233.     register int i;
  234.     vtype        buf;
  235.  
  236.     for (i = 0; i < 6; i++) {
  237.     cnv_stat(py.stats.use_stat[i], buf);
  238.     put_buffer(stat_names[i], 2 + i, 61);
  239.     put_buffer(buf, 2 + i, 66);
  240.     if (py.stats.max_stat[i] > py.stats.cur_stat[i]) {
  241.         cnv_stat(py.stats.max_stat[i], buf);
  242.         put_buffer(buf, 2 + i, 73);
  243.     }
  244.     }
  245. }
  246. #endif
  247.  
  248. /* Allows player to select a race            -JWT-     */
  249. static void
  250. choose_race()
  251. {
  252.     register int         j, k;
  253.     int                  l, m, exit_flag;
  254.     char                 s;
  255.     char                 tmp_str[80];
  256.     register player_type *p_ptr;
  257.     register race_type   *r_ptr;
  258.  
  259.     j = 0;
  260.     k = 0;
  261.     l = 2;
  262.     m = 21;
  263.     clear_from(20);
  264.     put_buffer("Choose a race (? for Help):", 20, 2);
  265.     do {
  266.     (void)sprintf(tmp_str, "%c) %s", k + 'a', race[j].trace);
  267.     put_buffer(tmp_str, m, l);
  268.     k++;
  269.     l += 15;
  270.     if (l > 70) {
  271.         l = 2;
  272.         m++;
  273.     }
  274.     j++;
  275.     }
  276.     while (j < MAX_RACES);
  277.     exit_flag = FALSE;
  278.     do {
  279.     move_cursor(20, 30);
  280.     s = inkey();
  281.     j = s - 'a';
  282.     if ((j < MAX_RACES) && (j >= 0))
  283.         exit_flag = TRUE;
  284.     else if (s == '?')
  285.         helpfile(ANGBAND_WELCOME);
  286.     else
  287.         bell();
  288.     }
  289.     while (!exit_flag);
  290.  
  291.     p_ptr = &py;
  292.     r_ptr = &race[j];
  293.     p_ptr->misc.prace = j;
  294.     put_buffer(r_ptr->trace, 3, 15);
  295. }
  296.  
  297.  
  298. /* Will print the history of a character            -JWT-     */
  299. static void
  300. print_history()
  301. {
  302.     register int        i;
  303.  
  304.     put_buffer("Character Background", 14, 27);
  305.     for (i = 0; i < 4; i++)
  306.     prt(py.misc.history[i], i + 15, 10);
  307. }
  308.  
  309.  
  310. static void
  311. set_prev_history()
  312. {
  313.     prev.bg.info = background->info;
  314.     prev.bg.roll = background->roll;
  315.     prev.bg.chart = background->chart;
  316.     prev.bg.next = background->next;
  317.     prev.bg.bonus = background->bonus;
  318.     prev.sc = py.misc.sc;
  319.  
  320.     (void)strncpy(prev.history[0], py.misc.history[0], 60);
  321.     (void)strncpy(prev.history[1], py.misc.history[1], 60);
  322.     (void)strncpy(prev.history[2], py.misc.history[2], 60);
  323.     (void)strncpy(prev.history[3], py.misc.history[3], 60);
  324.  
  325.     return;
  326. }
  327.  
  328.  
  329. static void
  330. get_prev_history()
  331. {
  332.     register int        i;
  333.  
  334.     background->info = prev.bg.info;
  335.     background->roll = prev.bg.roll;
  336.     background->chart = prev.bg.chart;
  337.     background->next = prev.bg.next;
  338.     background->bonus = prev.bg.bonus;
  339.     py.misc.sc = prev.sc;
  340.  
  341.     for (i = 0; i < 4; i++)
  342.     strncpy(py.misc.history[i], prev.history[i], 60);
  343. }
  344.  
  345.  
  346. /* Get the racial history, determines social class    -RAK-     */
  347. /* Assumptions:    Each race has init history beginning at
  348.  * (race-1)*3+1
  349.  * All history parts are in ascending order
  350.  */
  351.  
  352. static void
  353. get_history()
  354. {
  355.     int                      hist_ptr, cur_ptr, test_roll, flag;
  356.     register int             start_pos, end_pos, cur_len;
  357.     int                      line_ctr, new_start = 0, social_class;
  358.     char                     history_block[240];
  359.     register background_type *b_ptr;
  360.  
  361. /* Get a block of history text                 */
  362.     if (py.misc.prace == 8)
  363.     hist_ptr = 1;
  364.     else if (py.misc.prace > 8)
  365.     hist_ptr = 2 * 3 + 1;
  366.     else
  367.     hist_ptr = py.misc.prace * 3 + 1;
  368.     history_block[0] = '\0';
  369.     social_class = randint(4);
  370.     cur_ptr = 0;
  371.     do {
  372.     flag = FALSE;
  373.     do {
  374.         if (background[cur_ptr].chart == hist_ptr) {
  375.         test_roll = randint(100);
  376.         while (test_roll > background[cur_ptr].roll)
  377.             cur_ptr++;
  378.         b_ptr = &background[cur_ptr];
  379.         (void)strcat(history_block, b_ptr->info);
  380.         social_class += b_ptr->bonus - 50;
  381.         if (hist_ptr > b_ptr->next)
  382.             cur_ptr = 0;
  383.         hist_ptr = b_ptr->next;
  384.         flag = TRUE;
  385.         } else
  386.         cur_ptr++;
  387.     }
  388.     while (!flag);
  389.     }
  390.     while (hist_ptr >= 1);
  391.  
  392. /* clear the previous history strings */
  393.     for (hist_ptr = 0; hist_ptr < 4; hist_ptr++)
  394.     py.misc.history[hist_ptr][0] = '\0';
  395.  
  396. /* Process block of history text for pretty output     */
  397.     start_pos = 0;
  398.     end_pos = strlen(history_block) - 1;
  399.     line_ctr = 0;
  400.     flag = FALSE;
  401.     while (history_block[end_pos] == ' ')
  402.     end_pos--;
  403.     do {
  404.     while (history_block[start_pos] == ' ')
  405.         start_pos++;
  406.     cur_len = end_pos - start_pos + 1;
  407.     if (cur_len > 60) {
  408.         cur_len = 60;
  409.         while (history_block[start_pos + cur_len - 1] != ' ')
  410.         cur_len--;
  411.         new_start = start_pos + cur_len;
  412.         while (history_block[start_pos + cur_len - 1] == ' ')
  413.         cur_len--;
  414.     } else
  415.         flag = TRUE;
  416.     (void)strncpy(py.misc.history[line_ctr], &history_block[start_pos],
  417.               cur_len);
  418.     py.misc.history[line_ctr][cur_len] = '\0';
  419.     line_ctr++;
  420.     start_pos = new_start;
  421.     }
  422.     while (!flag);
  423.  
  424. /* Compute social class for player             */
  425.     if (social_class > 100)
  426.     social_class = 100;
  427.     else if (social_class < 1)
  428.     social_class = 1;
  429.     py.misc.sc = social_class;
  430. }
  431.  
  432.  
  433. /* Gets the character's sex                -JWT-     */
  434. static void
  435. get_sex()
  436. {
  437.     register int        exit_flag;
  438.     char                c;
  439.  
  440.     exit_flag = FALSE;
  441.     clear_from(20);
  442.     put_buffer("Choose a sex (? for Help):", 20, 2);
  443.     put_buffer("m) Male       f) Female", 21, 2);
  444.     do {
  445.     move_cursor(20, 29);
  446.     /* speed not important here */
  447.     c = inkey();
  448.     if (c == 'f' || c == 'F') {
  449.         py.misc.male = FALSE;
  450.         put_buffer("Female", 4, 15);
  451.         exit_flag = TRUE;
  452.     } else if (c == 'm' || c == 'M') {
  453.         py.misc.male = TRUE;
  454.         put_buffer("Male", 4, 15);
  455.         exit_flag = TRUE;
  456.     } else if (c == '?')
  457.         helpfile(ANGBAND_WELCOME);
  458.     else
  459.         bell();
  460.     }
  461.     while (!exit_flag);
  462. }
  463.  
  464.  
  465. /* Computes character's age, height, and weight        -JWT-     */
  466. static void
  467. get_ahw()
  468. {
  469.     register int        i;
  470.  
  471.     i = py.misc.prace;
  472.     py.misc.age = race[i].b_age + randint((int)race[i].m_age);
  473.     if (py.misc.male) {
  474.     py.misc.ht = randnor((int)race[i].m_b_ht, (int)race[i].m_m_ht);
  475.     py.misc.wt = randnor((int)race[i].m_b_wt, (int)race[i].m_m_wt);
  476.     } else {
  477.     py.misc.ht = randnor((int)race[i].f_b_ht, (int)race[i].f_m_ht);
  478.     py.misc.wt = randnor((int)race[i].f_b_wt, (int)race[i].f_m_wt);
  479.     }
  480.     py.misc.disarm += race[i].b_dis;
  481. }
  482.  
  483.  
  484. static void
  485. set_prev_ahw()
  486. {
  487.     prev.age = py.misc.age;
  488.     prev.wt = py.misc.wt;
  489.     prev.ht = py.misc.ht;
  490.     prev.disarm = py.misc.disarm;
  491.  
  492.     return;
  493. }
  494.  
  495.  
  496. static void
  497. get_prev_ahw()
  498. {
  499.     py.misc.age = prev.age;
  500.     py.misc.wt = prev.wt;
  501.     py.misc.ht = prev.ht;
  502.     py.misc.disarm = prev.disarm;
  503.     prev.age = prev.wt = prev.ht = prev.disarm = 0;
  504. }
  505.  
  506.  
  507. /* Gets a character class                -JWT-     */
  508. static void
  509. get_class()
  510. {
  511.     register int        i;
  512.     int                 min_value, max_value;
  513.     int                 percent;
  514.     char                buf[50];
  515.     register struct misc *m_ptr;
  516.     register player_type *p_ptr;
  517.     class_type         *c_ptr;
  518.  
  519.     c_ptr = &class[py.misc.pclass];
  520.     p_ptr = &py;
  521.     change_stat(A_STR, c_ptr->madj_str);
  522.     change_stat(A_INT, c_ptr->madj_int);
  523.     change_stat(A_WIS, c_ptr->madj_wis);
  524.     change_stat(A_DEX, c_ptr->madj_dex);
  525.     change_stat(A_CON, c_ptr->madj_con);
  526.     change_stat(A_CHR, c_ptr->madj_chr);
  527.  
  528.     for (i = 0; i < 6; i++) {
  529.     p_ptr->stats.cur_stat[i] = p_ptr->stats.max_stat[i];
  530.     p_ptr->stats.use_stat[i] = p_ptr->stats.max_stat[i];
  531.     }
  532.     p_ptr->misc.ptodam = todam_adj();           /* Real values         */
  533.     p_ptr->misc.ptohit = tohit_adj();
  534.     p_ptr->misc.ptoac = toac_adj();
  535.     p_ptr->misc.pac = 0;
  536.     p_ptr->misc.dis_td = p_ptr->misc.ptodam;    /* Displayed values     */
  537.     p_ptr->misc.dis_th = p_ptr->misc.ptohit;
  538.     p_ptr->misc.dis_tac = p_ptr->misc.ptoac;
  539.     p_ptr->misc.dis_ac = p_ptr->misc.pac + p_ptr->misc.dis_tac;
  540.  
  541. /* now set misc stats, do this after setting stats because of con_adj() for
  542.  * hitpoints 
  543.  */
  544.     m_ptr = &py.misc;
  545.     m_ptr->hitdie += c_ptr->adj_hd;
  546.     m_ptr->mhp = con_adj() + m_ptr->hitdie;
  547.     m_ptr->chp = m_ptr->mhp;
  548.     m_ptr->chp_frac = 0;
  549.  
  550. /* initialize hit_points array: put bounds on total possible hp,
  551.  * only succeed if it is within 1/8 of average value
  552.  */
  553.     min_value = (MAX_PLAYER_LEVEL * 3 * (m_ptr->hitdie - 1)) / 8 +
  554.     MAX_PLAYER_LEVEL;
  555.     max_value = (MAX_PLAYER_LEVEL * 5 * (m_ptr->hitdie - 1)) / 8 +
  556.     MAX_PLAYER_LEVEL;
  557.  
  558.     player_hp[0] = m_ptr->hitdie;
  559.     do {
  560.     for (i = 1; i < MAX_PLAYER_LEVEL; i++) {
  561.         player_hp[i] = randint((int)m_ptr->hitdie);
  562.         player_hp[i] += player_hp[i - 1];
  563.     }
  564.     }
  565.     while ((player_hp[MAX_PLAYER_LEVEL - 1] < min_value) ||
  566.        (player_hp[MAX_PLAYER_LEVEL - 1] > max_value));
  567.  
  568.     if (peek) {
  569.     percent = (int)(((long)player_hp[MAX_PLAYER_LEVEL - 1] * 200L) /
  570.         (m_ptr->hitdie + ((MAX_PLAYER_LEVEL - 1) * m_ptr->hitdie)));
  571.     sprintf(buf, "%d%% Life Rating", percent);
  572.     msg_print(buf);
  573.     }
  574.     m_ptr->bth += c_ptr->mbth;
  575.     m_ptr->bthb += c_ptr->mbthb;   /* RAK */
  576.     m_ptr->srh += c_ptr->msrh;
  577.     m_ptr->disarm = c_ptr->mdis + todis_adj();
  578.     m_ptr->fos += c_ptr->mfos;
  579.     m_ptr->stl += c_ptr->mstl;
  580.     m_ptr->save += c_ptr->msav;
  581.     m_ptr->expfact += c_ptr->m_exp;
  582. }
  583.  
  584. void
  585. rerate()
  586. {
  587.     int         min_value, max_value, i, percent;
  588.     char        buf[50];
  589.     struct misc *m_ptr = &py.misc;
  590.  
  591.     min_value = (MAX_PLAYER_LEVEL * 3 * (m_ptr->hitdie - 1)) / 8 +
  592.     MAX_PLAYER_LEVEL;
  593.     max_value = (MAX_PLAYER_LEVEL * 5 * (m_ptr->hitdie - 1)) / 8 +
  594.     MAX_PLAYER_LEVEL;
  595.     player_hp[0] = m_ptr->hitdie;
  596.     do {
  597.     for (i = 1; i < MAX_PLAYER_LEVEL; i++) {
  598.         player_hp[i] = randint((int)m_ptr->hitdie);
  599.         player_hp[i] += player_hp[i - 1];
  600.     }
  601.     }
  602.     while ((player_hp[MAX_PLAYER_LEVEL - 1] < min_value) ||
  603.        (player_hp[MAX_PLAYER_LEVEL - 1] > max_value));
  604.  
  605.     percent = (int)(((long)player_hp[MAX_PLAYER_LEVEL - 1] * 200L) /
  606.         (m_ptr->hitdie + ((MAX_PLAYER_LEVEL - 1) * m_ptr->hitdie)));
  607.  
  608.     sprintf(buf, "%d%% Life Rating", percent);
  609.     calc_hitpoints();
  610.     prt_stat_block();
  611.     msg_print(buf);
  612. }
  613.  
  614. /* Gets a character class                -JWT-     */
  615. static void
  616. get_class_choice()
  617. {
  618.     register int i, j;
  619.     int          k, l, m;
  620.     int          cl[MAX_CLASS], exit_flag;
  621.     class_type   *c_ptr;
  622.     char         tmp_str[80], s;
  623.     int32u       mask;
  624.  
  625.     for (j = 0; j < MAX_CLASS; j++)
  626.     cl[j] = 0;
  627.     i = py.misc.prace;
  628.     j = 0;
  629.     k = 0;
  630.     l = 2;
  631.     m = 21;
  632.     mask = 0x1;
  633.     clear_from(20);
  634.     put_buffer("Choose a class (? for Help):", 20, 2);
  635.     do {
  636.     if (race[i].rtclass & mask) {
  637.         (void)sprintf(tmp_str, "%c) %s", k + 'a', class[j].title);
  638.         put_buffer(tmp_str, m, l);
  639.         cl[k] = j;
  640.         l += 15;
  641.         if (l > 70) {
  642.         l = 2;
  643.         m++;
  644.         }
  645.         k++;
  646.     }
  647.     j++;
  648.     mask <<= 1;
  649.     }
  650.     while (j < MAX_CLASS);
  651.     py.misc.pclass = 0;
  652.     exit_flag = FALSE;
  653.     do {
  654.     move_cursor(20, 31);
  655.     s = inkey();
  656.     j = s - 'a';
  657.     if ((j < k) && (j >= 0)) {
  658.         py.misc.pclass = cl[j];
  659.         c_ptr = &class[py.misc.pclass];
  660.         exit_flag = TRUE;
  661.         clear_from(20);
  662.         put_buffer(c_ptr->title, 5, 15);
  663.     } else if (s == '?')
  664.         helpfile(ANGBAND_WELCOME);
  665.     else
  666.         bell();
  667.     } while (!exit_flag);
  668. }
  669.  
  670.  
  671. /* Given a stat value, return a monetary value, which affects the amount of
  672.  * gold a player has. 
  673.  */
  674. static int
  675. monval(i)
  676.     int                 i;
  677. {
  678.     return 5 * ((int)i - 10);
  679. }
  680.  
  681.  
  682. static void
  683. get_money()
  684. {
  685.     register int        tmp, gold;
  686.     register int16u    *a_ptr;
  687.  
  688.     a_ptr = py.stats.max_stat;
  689.     tmp = monval(a_ptr[A_STR]) + monval(a_ptr[A_INT])
  690.     + monval(a_ptr[A_WIS]) + monval(a_ptr[A_CON])
  691.     + monval(a_ptr[A_DEX]);
  692.  
  693.     gold = py.misc.sc * 6 + randint(25) + 325;          /* Social Class adj */
  694.     gold -= tmp;           /* Stat adj */
  695.     gold += monval(a_ptr[A_CHR]);  /* Charisma adj     */
  696.     if (!py.misc.male)
  697.     gold += 50;           /* She charmed the banker into it! -CJS- */
  698.                    /* She slept with the banker.. :) -GDH-  */
  699.     if (gold < 80)
  700.     gold = 80;           /* Minimum */
  701.     py.misc.au = gold;
  702. }
  703.  
  704.  
  705. /* ---------- M A I N  for Character Creation Routine ---------- */
  706. /* -JWT-     */
  707. void
  708. create_character()
  709. {
  710.     register char       c;
  711.  
  712. #ifdef AUTOROLLER
  713.     int32u       auto_round = 0;
  714.     register int i;
  715.     int          stat[6];
  716.     int          autoroll = 0;
  717.     int          msstat = 0;/* Max autoroll w/ look for -SAC */
  718.     class_type   *cptr;
  719.     race_type    *rptr;
  720.     char         inp[60];
  721.  
  722. #endif
  723.     int previous_exists = 0;    /* flag to prevent prev from garbage values */
  724.  
  725.     town_seed = random();    /* Change random seeds for new characters -CWS */
  726.     randes_seed = random();
  727.  
  728.     put_character();
  729.     choose_race();
  730.     get_sex();
  731.     get_class_choice();
  732.  
  733. #ifdef AUTOROLLER
  734. /*
  735.  * This auto-roller stolen from a post on rec.games.moria, which I belive was
  736.  * taken from druid moria 5.something.  If this intrudes on someone's
  737.  * copyright, take it out, and someone let me know -CFT 
  738.  */
  739.  
  740.     put_buffer("Do you want to use automatic rolling? (? for Help) ", 20, 2);
  741.     do {   /* allow multiple key entry, so they can ask for help and
  742.             * still get back to this menu... -CFT */
  743.  
  744.     move_cursor(20, 52);
  745.     c = inkey();
  746.     if (c == '?')
  747.         helpfile(ANGBAND_WELCOME);
  748.     } while ((c != 'y') && (c != 'Y') && (c != 'n') && (c != 'N'));
  749.  
  750.     if ((c == 'Y') || (c == 'y')) {
  751.     autoroll = 1;
  752.     clear_from(15);
  753.     cptr = &class[py.misc.pclass];
  754.     rptr = &race[py.misc.prace];
  755.     put_buffer("Enter minimum attribute for: ", 15, 2);
  756.     for (i = 0; i < 6; i++) {
  757.         int                 stat_idx = 0;
  758.  
  759.         switch (i) {
  760.           case 0:
  761.         stat_idx = A_STR;
  762.         clear_from(16 + i);
  763.         msstat = adjust_stat(17, cptr->madj_str+rptr->str_adj, TRUE);
  764.         sprintf(inp, "    Strength (Max of %2d): ", msstat);
  765.         put_buffer(inp, 16 + i, 5);
  766.         break;
  767.           case 1:
  768.         stat_idx = A_INT;
  769.         clear_from(16 + i);
  770.         msstat = adjust_stat(17, cptr->madj_int+rptr->int_adj, TRUE);
  771.         sprintf(inp, "Intelligence (Max of %2d): ", msstat);
  772.         put_buffer(inp, 16 + i, 5);
  773.         break;
  774.           case 2:
  775.         stat_idx = A_WIS;
  776.         clear_from(16 + i);
  777.         msstat = adjust_stat(17, cptr->madj_wis+rptr->wis_adj, TRUE);
  778.         sprintf(inp, "      Wisdom (Max of %2d): ", msstat);
  779.         put_buffer(inp, 16 + i, 5);
  780.         break;
  781.           case 3:
  782.         stat_idx = A_DEX;
  783.         clear_from(16 + i);
  784.         msstat = adjust_stat(17, cptr->madj_dex+rptr->dex_adj, TRUE);
  785.         sprintf(inp, "   Dexterity (Max of %2d): ", msstat);
  786.         put_buffer(inp, 16 + i, 5);
  787.         break;
  788.           case 4:
  789.         stat_idx = A_CON;
  790.         clear_from(16 + i);
  791.         msstat = adjust_stat(17, cptr->madj_con+rptr->con_adj, TRUE);
  792.         sprintf(inp, "Constitution (Max of %2d): ", msstat);
  793.         put_buffer(inp, 16 + i, 5);
  794.         break;
  795.           case 5:
  796.         stat_idx = A_CHR;
  797.         clear_from(16 + i);
  798.         msstat = adjust_stat(17, cptr->madj_chr+rptr->chr_adj, TRUE);
  799.         sprintf(inp, "    Charisma (Max of %2d): ", msstat);
  800.         put_buffer(inp, 16 + i, 5);
  801.         break;
  802.         } /* switch */
  803.         do {
  804.         inp[0] = '\000';
  805.         get_string(inp, 16 + i, 32, 3);
  806.         stat[stat_idx] = atoi(inp); /* have return give a stat of 3 */
  807.         if (inp[0] == '\015' || inp[0] == '\012' || inp[0] == '\000')
  808.             stat[stat_idx] = 3;
  809.         if (stat[stat_idx] < 0) {
  810.             stat[stat_idx] = (-stat[stat_idx]);
  811.             if (stat[stat_idx] > msstat)
  812.             msstat = stat[stat_idx];
  813.         }
  814.         } while (stat[stat_idx] > msstat || stat[stat_idx] < 3);
  815.     } /* for i 0 - 5 */
  816.     put_qio();
  817.     }
  818. #endif                   /* AUTOROLLER - main setup code */
  819.  
  820.     do {               /* Main generation loop */
  821.     clear_from(9);
  822. #ifdef AUTOROLLER
  823.     if (autoroll)
  824.         for (i = 2; i < 6; i++)
  825.         erase_line(i, 30);
  826.     do {               /* Start of AUTOROLLing loop */
  827. #endif
  828.         get_all_stats();
  829.         get_class();
  830.  
  831. #ifdef AUTOROLLER
  832.         if (autoroll) {
  833.         put_auto_stats();
  834.         auto_round++;
  835.         sprintf(inp, "auto-rolling round #%lu.", (long)auto_round);
  836.         put_buffer(inp, 20, 2);
  837. #if defined(unix) && defined(NICE)
  838.         usleep((long)100000L);
  839. #endif
  840.         put_qio();
  841.         } else
  842.         put_stats();
  843.     } while ((autoroll) &&
  844.          ((stat[A_STR] > py.stats.cur_stat[A_STR]) ||
  845.           (stat[A_INT] > py.stats.cur_stat[A_INT]) ||
  846.           (stat[A_WIS] > py.stats.cur_stat[A_WIS]) ||
  847.           (stat[A_DEX] > py.stats.cur_stat[A_DEX]) ||
  848.           (stat[A_CON] > py.stats.cur_stat[A_CON]) ||
  849.           (stat[A_CHR] > py.stats.cur_stat[A_CHR]))
  850.  
  851. #if (defined (unix) || defined(ATARI_ST)) /* CFT's if/elif/else    */
  852.          && (!check_input(1)));      /* unix needs flush here */
  853. #elif (defined(MSDOS) || defined(VMS))
  854.     &&(!kbhit()));
  855.     if (kbhit())
  856.         flush();
  857. #else
  858.     );
  859. #endif                   /* character checks */
  860. #endif                   /* AUTOROLLER main looping section */
  861.        get_history();               /* Common stuff */
  862.        get_ahw();
  863.  
  864.     calc_bonuses();
  865.     print_history();
  866.     put_misc1();
  867.     clear_from(20);
  868.  
  869.     do {               /* Input loop */
  870.         if (previous_exists) {
  871.         put_buffer("Hit space: Reroll, ^P: Previous or ESC: Accept: ",
  872.                20, 2);
  873.         move_cursor(20, 50);
  874.         } else {
  875.         put_buffer("Hit space: Reroll, or ESC: Accept: ", 20, 2);
  876.         move_cursor(20, 37);
  877.         }
  878.         c = inkey();
  879.         if ((previous_exists) && (c == CTRL('P'))) {
  880.         previous_exists = FALSE;
  881.         if (get_prev_stats()) {
  882.             get_prev_history();
  883.             get_prev_ahw();
  884.             print_history();
  885.             put_misc1();
  886.             calc_bonuses();
  887.             put_stats();
  888.             clear_from(20);
  889.         }
  890.         } else if ((c != ' ') && (c != ESCAPE))    /* Prolly better way to do this */
  891.         bell();
  892.     } while ((c != ' ') && (c != ESCAPE));
  893.  
  894. /* Not going to waste space w/ a check here. So ESC takes a little longer. -SAC */
  895.     set_prev_stats();
  896.     set_prev_history();
  897.     set_prev_ahw();
  898.     previous_exists = TRUE;
  899.     } while (c == ' ');
  900.     get_money();
  901.     put_stats();
  902.     put_misc2();
  903.     put_misc3();
  904.     get_name();
  905.     msg_print(NULL);
  906.  
  907. /* This delay may be reduced, but is recommended to keep players
  908.  * from continuously rolling up characters, which can be VERY
  909.  * expensive CPU wise.
  910.  */
  911.     pause_exit(23, PLAYER_EXIT_PAUSE);
  912. }
  913.